// src/router/index.js
import { createRouter, createWebHistory } from "vue-router";
import { baseRoutes } from "./routes";

// 导入组件（按需导入）
const routes = [
  ...baseRoutes,
];

const router = createRouter({
  history: createWebHistory(), // 使用 HTML5 History 模式
  routes,
});
// --在全局守卫中使用
router.beforeEach((to, from, next) => {
  if (to.meta.requiresAuth && !isLoggedIn()) {
    next("/login");
  } else {
    next();
  }
});
router.afterEach((to) => {
  document.title = (to.meta.title as string) || "火云山系统";
});
function isLoggedIn() {
  return !!localStorage.getItem("token"); // 检查是否存在 token
}
export default router;
